package com.ftg.learn;

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;

import java.util.Arrays;
import java.util.Collections;

/**
 * @author 布衣
 */
public class CreateImage {

    public static void main(String[] args) throws NoApiKeyException, UploadFileException {
        Constants.apiKey="sk-510b917932744b3680b858b474fbd919";
        Constants.baseHttpApiUrl="https://dashscope.aliyuncs.com/api/v1";

        MultiModalConversation conv = new MultiModalConversation();

        MultiModalMessage message = MultiModalMessage.builder()
                .role(Role.USER.getValue())
                .content(Arrays.asList(Collections.singletonMap("text","生成一个1024*768的图片，一个温馨的小屋，房间是有一个粉色的猫，做在桌子上面吃鱼，鱼骨给了川普吃")))
                .build();

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .model("qwen-image")
                .messages(Arrays.asList(message))
                .build();

        MultiModalConversationResult call = conv.call(param);

        System.out.println("生成以后的图片地址为"+ call.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("image").toString());

    }
}
